package leetcode;

/**
 * Created by Ghost on 2015/2/4.
 */
public class Implement_strStr {
    public int strStr(String haystack, String needle) {
        if(haystack.length()==0 && needle.length()==0)
            return 0;
        if(needle.length()>haystack.length())
            return -1;
        char[] h = haystack.toCharArray();
        char[] n = needle.toCharArray();
        for(int i=0;i<h.length;i++){
            int j=0;
            int l=i;
            while(j<n.length && l<h.length && n[j]==h[l]){
                j++;
                l++;
            }
            if(j==n.length){
                return l-j;
            }
        }
        return -1;
    }

    public static void main(String[] args){
        Implement_strStr implement_strStr = new Implement_strStr();
        System.out.println(implement_strStr.strStr("mississippi","issipi"));
        System.out.println("mississippi".indexOf("issipi"));
    }
}
